package com.yzkj.framework.beans.result;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageParams<E> {

    private int page;

    private int limit;

    private E entity;

    private List<SortParams> orderBy;

    public PageParams() {
        this.page = 0;
        this.limit = 0;
        this.entity = null;
        this.orderBy = new ArrayList<>();
    }

    public PageParams(int page, int limit, E entity, List<SortParams> orderBy) {
        this.page = page;
        this.limit = limit;
        this.entity = entity;
        this.orderBy = orderBy;
    }

    public PageParams(int page, int limit, E entity) {
        this.page = page;
        this.limit = limit;
        this.entity = entity;
        this.orderBy = new ArrayList<>();
    }

    public PageParams(int page, int limit) {
        this.page = page;
        this.limit = limit;
        this.entity = null;
        this.orderBy = new ArrayList<>();
    }

    /**
     * 若page和limit均为0，应返回所有数据，而非分页后的数据
     */
    public boolean isAll() {
        return page == 0 && limit == 0;
    }
}
